<template>
	<view class="content">
		<table>
			<tr>
				<td>产品查询</td>
				<td><input type="text" v-model="name" style="background-color: antiquewhite;"></td>
				<view style="display: flex;">
					<button @click="add()">去添加</button>
					<button @click="ss()">搜索</button>
				</view>
			</tr>
			<tr>
				<td>产品名称</td>
				<td>产品价格</td>
				<td>产品状态</td>
				<td>操作</td>
			</tr>

			<tr v-for="v in list">
				<td>{{v.Name}}</td>
				<td>{{v.Prince}}</td>
				<td>{{v.Status}}</td>
				<td style="display: flex;">
				<button @click="del(v.ID)">删除</button>
				<button @click="show(v.ID)">编辑</button>
				</td>
			</tr>
		</table>
		
		<uni-pagination title="标题文字" show-icon="true" :total="allpage" :current="page" :page-size="size" @change="fy"></uni-pagination>
		



	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:"",
				list: [],
				page : 1,
				size : 5,
				allpage : 0,
			}
		},
		onShow() {
			this.get_data()
		},
		methods: {
			show(id){
				uni.navigateTo({
					url:"/pages/show/show?id="+id
				})
			},
			fy(e){
				console.log(e.current)
				this.page = e.current
				this.get_data()
			},
			get_data() {
				uni.request({
					url: 'http://127.0.0.1:8080/list', //仅为示例，并非真实接口地址。
					data: {
						name:this.name,
						page : this.page,
						size : this.size,
					},
					method: "GET",
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					success: (res) => {
						console.log(res.data)
						this.list = res.data.Data
						this.allpage = res.data.AllPage
					}
				});
			},
			del(id) {
				console.log(id)
				uni.request({
					url: 'http://127.0.0.1:8080/del', //仅为示例，并非真实接口地址。
					data: {
						id: id,
					},
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					success: (res) => {
						console.log(res.data)
						if (res.data.Cre == 200) {
							alert("删除成功")
							this.get_data()
						} else {
							alert("删除失败")
						}

					}
				});
			},
			add(){
				uni.navigateTo({
					url:"/pages/add/add",
				})
			},
			ss(){
				this.get_data()
			},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>